package com.online.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.online.pojo.Classify;
import com.online.service.ClassifyService;
import com.online.mapper.ClassifyMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
* @author HDDN
* @description 针对表【on_classify】的数据库操作Service实现
* @createDate 2025-02-03 11:25:25
*/
@Service
public class ClassifyServiceImpl implements ClassifyService{
    @Autowired
    private ClassifyMapper iClassifyMapper;

    @Override
    public List<Classify> selectAll() {
        LambdaQueryWrapper <Classify> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Classify::getIsDelete,0);
        return iClassifyMapper.selectList(lqw);
    }


    @Override
    public List<Classify> selectList(Classify iClassify) {
        LambdaQueryWrapper <Classify> lqw = this.lqw(iClassify);
        return iClassifyMapper.selectList(lqw);
    }

    @Override
    public Integer insert(Classify iClassify) {
        return iClassifyMapper.insert(iClassify);
    }

    @Override
    @Transactional
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                Classify iClassify = new Classify();
                iClassify.setClassifyId(Long.parseLong(id));
                iClassify.setIsDelete(1);
                iClassifyMapper.updateById(iClassify);
            }
            return 1;
        }catch (Exception e){
            return -1;
        }
    }

    @Override
    public Integer update(Classify iClassify) {
        return iClassifyMapper.updateById(iClassify);
    }

    @Override
    public Page<Classify> pageAll(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<Classify>)this.selectAll();
    }

    @Override
    public Page<Classify> pageList(Classify iClassify, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<Classify>)this.selectList(iClassify);
    }

    public LambdaQueryWrapper lqw(Classify iClassify){
        LambdaQueryWrapper <Classify> lqw = new LambdaQueryWrapper<>();
        if (iClassify.getClassifyId() != null){
            lqw.eq(Classify::getClassifyId,iClassify.getClassifyId());
        }
        if (iClassify.getClassifyName() != null){
            lqw.eq(Classify::getClassifyName,iClassify.getClassifyName());
        }
        if (iClassify.getIsDelete() != null){
            lqw.eq(Classify::getIsDelete,iClassify.getIsDelete());
        }
        if (iClassify.getCreateTime() != null){
            lqw.eq(Classify::getCreateTime,iClassify.getCreateTime());
        }
        if (iClassify.getUpdateTime() != null){
            lqw.eq(Classify::getUpdateTime,iClassify.getUpdateTime());
        }
        if (iClassify.getDescription() != null){
            lqw.eq(Classify::getDescription,iClassify.getDescription());
        }
        return lqw;
    }
}




